package com.nifostasky.comic.controller;

import com.nifostasky.comic.entitys.SysOrg;
import com.nifostasky.comic.service.SysOrgService;
import com.nifostasky.comic.utils.PageUtils;
import com.nifostasky.comic.vos.JsonResult;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysOrg")
@Api(tags = "行政区域管理", position = 6)
@AllArgsConstructor
public class SysOrgController {
    private SysOrgService sysOrgService;

    @ApiOperation(value = "分页列表",notes = "带参分页查询列表")
    @GetMapping("findListPage")
    @ApiOperationSupport(order = 1)
    public JsonResult findListPage(PageUtils pageUtils, SysOrg sysOrg){
        return new JsonResult(sysOrgService.findListPage(pageUtils, sysOrg));
    }

    @ApiOperation(value = "列表",notes = "带参不分页查询列表")
    @GetMapping("findList")
    @ApiOperationSupport(order = 2)
    public JsonResult findListPage(SysOrg sysOrg){
        return new JsonResult(sysOrgService.findList(sysOrg));
    }

    @ApiOperation("新增/修改")
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 3)
    public JsonResult saveOrUpdate(@RequestBody SysOrg sysOrg){
        return new JsonResult(sysOrgService.saveOrUpdateOrg(sysOrg));
    }

    @ApiOperation("根据主键id获取信息")
    @GetMapping("/getData")
    @ApiResponses(@ApiResponse(code = 200,message = "返回成功",response = SysOrg.class))
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "主键id", dataType = "Int",required = true)
    )
    @ApiOperationSupport(order = 4)
    public JsonResult<SysOrg> getData(Long id){
        return new JsonResult(sysOrgService.getById(id));
    }

    @ApiOperation("启用/禁用")
    @GetMapping("/updateOrgStatusById")
    @ApiOperationSupport(order = 5)
    public JsonResult updateOrgStatusById(@ApiParam("主键id") Long id,@ApiParam("区域状态:1启用，2禁用")Integer orgStatus){
        return new JsonResult(sysOrgService.updateOrgStatusById(id,orgStatus));
    }

    @ApiOperation("单个删除")
    @GetMapping("/deleteById")
    @ApiOperationSupport(order = 6)
    public JsonResult deleteById(@ApiParam("主键id") Long id){
        return new JsonResult(sysOrgService.deleteById(id));
    }
}
